/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Modulo1;

import Modelo.DAL.PreReporte_DAO;
import Acceso.Security;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONObject;

/**
 *
 * @author miguel474
 */
public class consultarPreReporteAction extends org.apache.struts.action.Action {

    private static final String SUCCESS = "success";
    private static final String FAILURE = "failure";

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        String[] a = {"Administrador", "Recibir Pre-Reportes"};
        if (!Security.validateSession(request, a)) {
            Security.privilegeError(response);
            return mapping.findForward("errorPriv");
        }

        String idPreReporte = request.getParameter("idPreReporte");
        if (idPreReporte == null || idPreReporte.equals("")) {
            return mapping.findForward(FAILURE);
        }

        response.setContentType("text/json");
        JSONObject jo = new JSONObject();
        jo.put("prInfo", PreReporte_DAO.getPR(idPreReporte));

        PrintWriter pw = response.getWriter();
        pw.write(jo.toString());
        pw.flush();
        pw.close();

        return mapping.findForward(SUCCESS);
    }
}
